function caculationByResTime(IDCARD,ArrivalTime1,ArrivalTime2,LeaveTime1,LeaveTime2,EmployeeId,dateType,DateDay,Url){
    var strURL = Url;
    $.ajax({
            url: strURL,
            type: 'POST',
            dataType: "json",
            cache: false,
            data: { IDCARD:IDCARD,employeeID:EmployeeId, Arrivaltime: Arrivaltime,Leavetime:Leavetime,dateType:dateType,DateDay:DateDay},
            success: function(string){
                if ($.isEmptyObject(string)){
                   // 
                }
                else{
                    var cResTime11 = PriceRestime1(string.ResTime1);
                    var cResTime12 = PriceRestime2(string.ResTime1);
                    var cResTime21 = PriceRestime1(string.ResTime2);
                    var cResTime22 = PriceRestime2(string.ResTime2);
                    var cResTime31 = PriceRestime1(string.ResTime3);
                    var cResTime32 = PriceRestime2(string.ResTime3);                                                               
                    var cActualWorkHours = getTimeWorking(string.ActualWorkHours);
                    var cWeekdayNormalTime = getTimeWorking(string.WeekdayNormalTime);
                    var cWeekdayOvertime = getTimeWorking(string.WeekdayOvertime);
                    var cWeekdayLateOvertime = getTimeWorking(string.WeekdayLateOvertime);
                    var cWeekendOvertime = getTimeWorking(string.WeekendOvertime);
                    var cWeekendLateOvertime = getTimeWorking(string.WeekendLateOvertime);
                    var cHolidayOvertime = getTimeWorking(string.HolidayOvertime);
                    var cHolidayLateOvertime = getTimeWorking(string.HolidayLateOvertime);
                    changeValue1(IDCARD,cResTime11,cResTime12,cResTime21,cResTime22,cResTime31,cResTime32,cActualWorkHours,cWeekdayNormalTime,cWeekdayOvertime,cWeekdayLateOvertime,cWeekendOvertime,cWeekendLateOvertime,cHolidayOvertime,cHolidayLateOvertime);									
                }
            }
    });    
}
function caculateNormalWorkTime(IDCARD,ArrivalTime1,ArrivalTime2,LeaveTime1,LeaveTime2,EmployeeId,DateDay,Url,ORGArrivalTime1,ORGArrivalTime2,ORGLeaveTime1,ORGLeaveTime2){  
        var strURL = Url;
        $.ajax({
                url: strURL,
                type: 'POST',
                cache: false,
                data: { employeeID:EmployeeId, ArrivalTime1: ArrivalTime1,ArrivalTime2:ArrivalTime2,LeaveTime1:LeaveTime1,LeaveTime2:LeaveTime2,ORGArrivalTime1:ORGArrivalTime1,ORGArrivalTime2:ORGArrivalTime2,ORGLeaveTime1:ORGLeaveTime1,ORGLeaveTime2:ORGLeaveTime2,DateDay:DateDay},
                success: function(string){
                        var getData = $.parseJSON(string);
                        var cResTime11 = PriceRestime1(getData.ResTime1);
                        var cResTime12 = PriceRestime2(getData.ResTime1);
                        var cResTime21 = PriceRestime1(getData.ResTime2);
                        var cResTime22 = PriceRestime2(getData.ResTime2);
                        var cResTime31 = PriceRestime1(getData.ResTime3);
                        var cResTime32 = PriceRestime2(getData.ResTime3);
                        var cActualWorkHours = getTimeWorking(getData.ActualWorkHours);
                        var cWeekdayNormalTime = getTimeWorking(getData.WeekdayNormalTime);
                        var cWeekdayOvertime = getTimeWorking(getData.WeekdayOvertime);
                        var cWeekdayLateOvertime = getTimeWorking(getData.WeekdayLateOvertime);
                        var cWeekendOvertime = getTimeWorking(getData.WeekendOvertime);
                        var cWeekendLateOvertime = getTimeWorking(getData.WeekendLateOvertime);
                        var cHolidayOvertime = getTimeWorking(getData.HolidayOvertime);
                        var cHolidayLateOvertime = getTimeWorking(getData.HolidayLateOvertime);
                        var WorkingHours01 = getTimeWorking(getData.WorkingHours);
                        changeValue(IDCARD,WorkingHours01,cResTime11,cResTime12,cResTime21,cResTime22,cResTime31,cResTime32,cActualWorkHours,cWeekdayNormalTime,cWeekdayOvertime,cWeekdayLateOvertime,cWeekendOvertime,cWeekendLateOvertime,cHolidayOvertime,cHolidayLateOvertime);									
                }
        });		
}
function caculateWeekendWorkTime(IDCARD,ArrivalTime1,ArrivalTime2,LeaveTime1,LeaveTime2,EmployeeId,DateDay,Url,ORGArrivalTime1,ORGArrivalTime2,ORGLeaveTime1,ORGLeaveTime2){
        var strURL = Url;
        $.ajax({
                url: strURL,
                type: 'POST',
                cache: false,
                data: { employeeID:EmployeeId, ArrivalTime1: ArrivalTime1,ArrivalTime2:ArrivalTime2,LeaveTime1:LeaveTime1,LeaveTime2:LeaveTime2,ORGArrivalTime1:ORGArrivalTime1,ORGArrivalTime2:ORGArrivalTime2,ORGLeaveTime1:ORGLeaveTime1,ORGLeaveTime2:ORGLeaveTime2,DateDay:DateDay},
                success: function(string){
                        var getData = $.parseJSON(string);
                        var cResTime11 = PriceRestime1(getData.ResTime1);
                        var cResTime12 = PriceRestime2(getData.ResTime1);
                        var cResTime21 = PriceRestime1(getData.ResTime2);
                        var cResTime22 = PriceRestime2(getData.ResTime2);
                        var cResTime31 = PriceRestime1(getData.ResTime3);
                        var cResTime32 = PriceRestime2(getData.ResTime3);
                        var cActualWorkHours = getTimeWorking(getData.ActualWorkHours);
                        var cWeekdayNormalTime = getTimeWorking(getData.WeekdayNormalTime);
                        var cWeekdayOvertime = getTimeWorking(getData.WeekdayOvertime);
                        var cWeekdayLateOvertime = getTimeWorking(getData.WeekdayLateOvertime);
                        var cWeekendOvertime = getTimeWorking(getData.WeekendOvertime);
                        var cWeekendLateOvertime = getTimeWorking(getData.WeekendLateOvertime);
                        var cHolidayOvertime = getTimeWorking(getData.HolidayOvertime);
                        var cHolidayLateOvertime = getTimeWorking(getData.HolidayLateOvertime);
                        var WorkingHours01 = getTimeWorking(getData.WorkingHours);
                        changeValue(IDCARD,WorkingHours01,cResTime11,cResTime12,cResTime21,cResTime22,cResTime31,cResTime32,cActualWorkHours,cWeekdayNormalTime,cWeekdayOvertime,cWeekdayLateOvertime,cWeekendOvertime,cWeekendLateOvertime,cHolidayOvertime,cHolidayLateOvertime);									
                }
        });		
}		
function caculateHolidayWorkTime(IDCARD,ArrivalTime1,ArrivalTime2,LeaveTime1,LeaveTime2,EmployeeId,DateDay,Url,ORGArrivalTime1,ORGArrivalTime2,ORGLeaveTime1,ORGLeaveTime2){   
        var strURL = Url;
        $.ajax({
                url: strURL,
                type: 'POST',
                cache: false,
                data: { employeeID:EmployeeId,ArrivalTime1: ArrivalTime1,ArrivalTime2:ArrivalTime2,LeaveTime1:LeaveTime1,LeaveTime2:LeaveTime2,ORGArrivalTime1:ORGArrivalTime1,ORGArrivalTime2:ORGArrivalTime2,ORGLeaveTime1:ORGLeaveTime1,ORGLeaveTime2:ORGLeaveTime2,DateDay:DateDay},
                success: function(string){
                        var getData = $.parseJSON(string);
                        var cResTime11 = PriceRestime1(getData.ResTime1);
                        var cResTime12 = PriceRestime2(getData.ResTime1);
                        var cResTime21 = PriceRestime1(getData.ResTime2);
                        var cResTime22 = PriceRestime2(getData.ResTime2);
                        var cResTime31 = PriceRestime1(getData.ResTime3);
                        var cResTime32 = PriceRestime2(getData.ResTime3);
                        var cActualWorkHours = getTimeWorking(getData.ActualWorkHours);
                        var cWeekdayNormalTime = getTimeWorking(getData.WeekdayNormalTime);
                        var cWeekdayOvertime = getTimeWorking(getData.WeekdayOvertime);
                        var cWeekdayLateOvertime = getTimeWorking(getData.WeekdayLateOvertime);
                        var cWeekendOvertime = getTimeWorking(getData.WeekendOvertime);
                        var cWeekendLateOvertime = getTimeWorking(getData.WeekendLateOvertime);
                        var cHolidayOvertime = getTimeWorking(getData.HolidayOvertime);
                        var cHolidayLateOvertime = getTimeWorking(getData.HolidayLateOvertime);	
                        changeValue(IDCARD,WorkingHours01,cResTime11,cResTime12,cResTime21,cResTime22,cResTime31,cResTime32,cActualWorkHours,cWeekdayNormalTime,cWeekdayOvertime,cWeekdayLateOvertime,cWeekendOvertime,cWeekendLateOvertime,cHolidayOvertime,cHolidayLateOvertime);									
                }
        });		
}
function reChangeInputOnchangeArrivalTime1(IDCARD,id_input,valueThis,ORGArrivalTime1,LeaveTime1,ArrivalTime2,LeaveTime2,urlchang1){
    var strURL = urlchang1;
    $.ajax({
        url: strURL,
        type: 'POST',
        cache: false,
        data: {ArrivalTime1:valueThis,ORGArrivalTime1:ORGArrivalTime1,LeaveTime1:LeaveTime1,ArrivalTime2:ArrivalTime2,LeaveTime2:LeaveTime2},
        success: function(string){
            $("tr#"+IDCARD).find("input#"+id_input).val(string);
        }
    });
}
function reChangeInputOnchangeLeaveTime1(IDCARD,id_input,valueThis,ORGLeaveTime1,ArrivalTime1,ArrivalTime2,LeaveTime2,urlchang1,EmployeeId,DateDay){
    var strURL = urlchang1;
    $.ajax({
        url: strURL,
        type: 'POST',
        cache: false,
        data: {LeaveTime1:valueThis,ORGLeaveTime1:ORGLeaveTime1,ArrivalTime1:ArrivalTime1,EmployeeId:EmployeeId,ArrivalTime2:ArrivalTime2,LeaveTime2:LeaveTime2,DateDay:DateDay},
        success: function(string){
            $("tr#"+IDCARD).find("input#"+id_input).val(string);
        }
    });
}         
function reChangeInputOnchange(IDCARD,id_input,valueThis,ORGTime,urlchang1){
    var strURL = urlchang1;
    $.ajax({
        url: strURL,
        type: 'POST',
        cache: false,
        data: { Time2:valueThis,ORGTime: ORGTime},
        success: function(string){
            $("tr#"+IDCARD).find("input#"+id_input).val(string);
        }
    });
}
function changeValue1(IDCARD,cResTime11,cResTime12,cResTime21,cResTime22,cResTime31,cResTime32,cActualWorkHours,cWeekdayNormalTime,cWeekdayOvertime,cWeekdayLateOvertime,cWeekendOvertime,cWeekendLateOvertime,cHolidayOvertime,cHolidayLateOvertime){
        $("tr#"+IDCARD).find("input#ResTime11").val(cResTime11);
        $("tr#"+IDCARD).find("input#ResTime12").val(cResTime12);
        $("tr#"+IDCARD).find("input#ResTime21").val(cResTime21);
        $("tr#"+IDCARD).find("input#ResTime22").val(cResTime22);
        $("tr#"+IDCARD).find("input#ResTime31").val(cResTime31);
        $("tr#"+IDCARD).find("input#ResTime32").val(cResTime32);
        $("tr#"+IDCARD).find("input#ActualWorkHours10").val(cActualWorkHours);
        $("tr#"+IDCARD).find("input#WeekdayNormalTime10").val(cWeekdayNormalTime);
        $("tr#"+IDCARD).find("input#WeekdayOvertime10").val(cWeekdayOvertime);
        $("tr#"+IDCARD).find("input#WeekdayLateOvertime10").val(cWeekdayLateOvertime);
        $("tr#"+IDCARD).find("input#WeekendOvertime10").val(cWeekendOvertime);
        $("tr#"+IDCARD).find("input#WeekendLateOvertime10").val(cWeekendLateOvertime);
        $("tr#"+IDCARD).find("input#HolidayOvertime10").val(cHolidayOvertime);
        $("tr#"+IDCARD).find("input#HolidayLateOvertime10").val(cHolidayLateOvertime);		
}     
function changeValue(IDCARD,WorkingHours01,cResTime11,cResTime12,cResTime21,cResTime22,cResTime31,cResTime32,cActualWorkHours,cWeekdayNormalTime,cWeekdayOvertime,cWeekdayLateOvertime,cWeekendOvertime,cWeekendLateOvertime,cHolidayOvertime,cHolidayLateOvertime){
        $("tr#"+IDCARD).find("td#WorkingHours").html(WorkingHours01);
        $("tr#"+IDCARD).find("input#ResTime11").val(cResTime11);
        $("tr#"+IDCARD).find("input#ResTime12").val(cResTime12);
        $("tr#"+IDCARD).find("input#ResTime21").val(cResTime21);
        $("tr#"+IDCARD).find("input#ResTime22").val(cResTime22);
        $("tr#"+IDCARD).find("input#ResTime31").val(cResTime31);
        $("tr#"+IDCARD).find("input#ResTime32").val(cResTime32);
        $("tr#"+IDCARD).find("input#ActualWorkHours10").val(cActualWorkHours);
        $("tr#"+IDCARD).find("input#WeekdayNormalTime10").val(cWeekdayNormalTime);
        $("tr#"+IDCARD).find("input#WeekdayOvertime10").val(cWeekdayOvertime);
        $("tr#"+IDCARD).find("input#WeekdayLateOvertime10").val(cWeekdayLateOvertime);
        $("tr#"+IDCARD).find("input#WeekendOvertime10").val(cWeekendOvertime);
        $("tr#"+IDCARD).find("input#WeekendLateOvertime10").val(cWeekendLateOvertime);
        $("tr#"+IDCARD).find("input#HolidayOvertime10").val(cHolidayOvertime);
        $("tr#"+IDCARD).find("input#HolidayLateOvertime10").val(cHolidayLateOvertime);		
}
function workingHours(H2,H1,M2,M1){
        var Mute = '';
        var Hour = '';
        if(parseInt(H2) > parseInt(H1)){
                if(parseInt(M2) < parseInt(M1)){
                        Mute = -( parseInt(M2) - parseInt(M1) );
                        Hour = H2 - H1 - 1;
                }
                else{
                        Mute = parseInt(M2) - parseInt(M1);
                        Hour = parseInt(H2) - parseInt(H1);
                }
                if(parseInt(Mute)==0){
                        return Hour+":"+Mute+"0";
                }
                else{
                        return Hour+":"+Mute;
                }
        }
        else{
                return "0:00";
        }
}
function PriceRestime1(restime){
        var restime1 = restime.toString().split(".");
        return restime1[0];
}
function PriceRestime2(restime){
        var restime1 = restime.toString().split(".");
        if(!isNaN(restime1[1])){
                if(parseInt(restime1[1])>10){
                        var getrestime1 = parseInt(parseInt(restime1[1])*60)/100;
                }
                else{
                        var getrestime1 = parseInt(parseInt(restime1[1])*60)/10;
                }
                var getrestime2 = getrestime1.toString().split(".");
                return getrestime2[0]; 
        }
        else{

                return "00"; 
        }		
}
function getTimeWorking(time){
        var Time = time.toString().split(".");
        if(!isNaN(Time[1])){
                if(parseInt(Time[1])>10){
                        var getMunite = parseInt(parseInt(Time[1])*60)/100;
                }
                else{
                        var getMunite = parseInt(parseInt(Time[1])*60)/10;
                }
                var Munite = getMunite.toString().split(".");

                return  Time[0]+":"+Munite[0]; 
        }
        else{
                return Time[0]+":"+"00";
        }
}
/*
 * @author :        HungLV
 * @created:        
 * @Description:    change all value data when select choose holiday
 * @Input :         (int) IDCARD
 * @Output :        
 */
function onChangeHoliday(IDCARD){
    $("tr#"+IDCARD).find("td#WorkingHours").html('0:00');
    $("tr#"+IDCARD).find("td#ActualArrivalTime").html('00:00:00');
    $("tr#"+IDCARD).find("td#ActualLeaveTime").html('00:00:00');
    $("tr#"+IDCARD).find("td#LeaveTime").html('00:00');
    $("tr#"+IDCARD).find("td#LateArrival").html('00:00');
    $("tr#"+IDCARD).find("td#EarlyArrival").html('00:00');
    $("tr#"+IDCARD).find("input#ArrivalTime1").val('00');
    $("tr#"+IDCARD).find("input#ArrivalTime2").val('00');
    $("tr#"+IDCARD).find("input#LeaveTime1").val('00');
    $("tr#"+IDCARD).find("input#LeaveTime2").val('00');
    $("tr#"+IDCARD).find("input#WorkingHours").html('0:00');
    $("tr#"+IDCARD).find("input#ResTime11").val('0');
    $("tr#"+IDCARD).find("input#ResTime12").val('00');
    $("tr#"+IDCARD).find("input#ResTime21").val('0');
    $("tr#"+IDCARD).find("input#ResTime22").val('00');
    $("tr#"+IDCARD).find("input#ResTime31").val('0');
    $("tr#"+IDCARD).find("input#ResTime32").val('00');
    $("tr#"+IDCARD).find("input#ActualWorkHours10").val('0:00');
    $("tr#"+IDCARD).find("input#WeekdayNormalTime10").val('0:00');   
    $("tr#"+IDCARD).find("input#WeekdayOvertime10").val('0:00');   
    $("tr#"+IDCARD).find("input#WeekdayLateOvertime10").val('0:00');   
    $("tr#"+IDCARD).find("input#WeekendOvertime10").val('0:00');   
    $("tr#"+IDCARD).find("input#WeekendLateOvertime10").val('0:00');   
    $("tr#"+IDCARD).find("input#HolidayOvertime10").val('0:00');   
    $("tr#"+IDCARD).find("input#HolidayLateOvertime10").val('0:00');   
    $("tr#"+IDCARD).find("input#WeekdayNormalTime").val('0:00');   
}
/*
 * @author :        HungLV
 * @created:        
 * @Description:    change all value data when select choose working
 * @Input :         (int) IDCARD
 * @Output :        
 */
function onChangeWorking(idCard,Url){
    var strURL = Url;
    // get all data input
    var ShiftType = $("tr#"+idCard).find("select#ShiftType").val();
    var ArrivalTime1 = $("tr#"+idCard).find("input#ArrivalTime1").val();
    var ArrivalTime2 = $("tr#"+idCard).find("input#ArrivalTime2").val();
    var LeaveTime1 = $("tr#"+idCard).find("input#LeaveTime1").val();
    var LeaveTime2 = $("tr#"+idCard).find("input#LeaveTime2").val();
    var Date = $("tr#"+idCard).find("td#Date").text();
    var EmployeeId = $("tr#"+idCard).find("input#EmployeeId").val();
    $.ajax({
            url: strURL,
            type: 'POST',
            cache: false,
            data: {Date:Date,EmployeeId:EmployeeId,ShiftType:ShiftType,ArrivalTime1: ArrivalTime1,ArrivalTime2:ArrivalTime2,LeaveTime1:LeaveTime1,LeaveTime2:LeaveTime2},
            success: function(string){
            }
    });    
}